/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_kernel.htm
 *
 * Zhiqim Kernel is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.kernel.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

import org.zhiqim.kernel.annotation.AnAlias;

/**
 * 非重复集合类静态扩展类
 *
 * @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
 */
@AnAlias("Setx")
public class Setx extends Collectionx
{
    // Query Operations 查询操作

    public static int size(Set<?> set)
    {
        return (set == null)?0:set.size();
    }

    public static boolean isEmpty(Set<?> set)
    {
        return (set == null)?true:set.isEmpty();
    }

    public static boolean contains(Set<?> set, Object o)
    {
        return (set == null)?false:set.contains(o);
    }

    public static <E> Iterator<E> iterator(Set<E> set)
    {
        return set.iterator();
    }

    public static Object[] toArray(Set<?> set)
    {
        return set.toArray();
    }

    public static <T> T[] toArray(Set<T> set, T[] a)
    {
        return set.toArray(a);
    }

    // Modification Operations 修改操作

    public static <E> boolean add(Set<E> set, E e)
    {
        return (set == null)?false:set.add(e);
    }

    public static boolean remove(Set<?> set, Object o)
    {
        return (set == null)?false:set.remove(o);
    }

    // Bulk Operations 批量操作

    public static boolean containsAll(Set<?> set, Collection<?> c)
    {
        return (set == null)?false:set.containsAll(c);
    }
   
    public static <E> boolean addAll(Set<E> set, Collection<? extends E> c)
    {
        return (set == null)?false:set.addAll(c);
    }

    public static boolean retainAll(Set<?> set, Collection<?> c)
    {
        return (set == null)?false:set.retainAll(c);
    }

    public static boolean removeAll(Set<?> set, Collection<?> c)
    {
        return (set == null)?false:set.removeAll(c);
    }

    public static void clear(Set<?> set)
    {
        if (set != null)set.clear();
    }

    // Comparison and hashing 

    public static boolean equals(Set<?> set, Object o)
    {
        return (set == null)?(o == null):set.equals(o);
    }

    public static int hashCode(Set<?> set)
    {
        return (set == null)?0:set.hashCode();
    }
}
